package com.mi.global.shop.common.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by laihengyu on 2017/11/15.
 */

public class Device {
    public static boolean IS_MIUI;

    public static void init(Context context) {
        IS_MIUI = isMiui(context);
    }

    /**
     * 通过判断CloudService是否存在来判断是否是miui，小米账户如果不存在的话认为不是miui
     */
    public static boolean isMiui(Context context) {
        PackageManager packageManager = context.getPackageManager();
        try {
            PackageInfo pkgInfo = packageManager.getPackageInfo("com.miui.cloudservice", 0);
            return (pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        } catch (Error e) {
            e.printStackTrace();
            return false;
        } catch (PackageManager.NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
    }

}
